<template>
  <view :style="themeColor">
    <view class="page">
      <fu-custom bgColor="bg-white" :isBack="true" :isBottom="true">
        <block slot="content">申请开票</block>
      </fu-custom>

      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout invoiceConfirm_flex_1"
        v-if=" info.type!=''">
        <view class='flex flex-direction align-stretch invoiceConfirm_fd1_0'>
          <view class='flex flex-wrap align-center justify-between invoiceConfirm_fd1_0_c0'>
            <text class='invoiceConfirm_fd1_0_c0_c0'>发票类型</text>
            <text class='invoiceConfirm_fd1_0_c0_c1'>电子发票</text>
          </view>
          <view class='flex flex-wrap align-center invoiceConfirm_fd1_0_c1'>
            <text class='invoiceConfirm_fd1_0_c1_c0'>发票信息</text>
          </view>
          <view class='flex flex-wrap align-center invoiceConfirm_fd1_0_c2'>
            <text class='invoiceConfirm_fd1_0_c2_c0'>抬头类型</text>
            <text class='invoiceConfirm_fd1_0_c2_c1' v-if="info.type=='1'">个人</text><text
              class='invoiceConfirm_fd1_0_c2_c1' v-if="info.type!='1'">公司</text>
          </view>
          <view class='flex flex-wrap align-center invoiceConfirm_fd1_0_c3'>
            <image class='invoiceConfirm_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='invoiceConfirm_fd1_0_c3_c1'>发票抬头</text>
            <input class='flex-sub invoiceConfirm_fd1_0_c3_c2' type="text" :placeholder="`发票抬头不能为空`" confirm-type="done"
              :maxlength="-1" placeholder-style="color:#BFBFBF;font-size:32rpx" v-model="info.username" />
          </view>
          <view class='flex flex-wrap align-center invoiceConfirm_fd1_0_c3' v-if="info.type!='1'">
            <image class='invoiceConfirm_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='invoiceConfirm_fd1_0_c3_c1'>公司税号</text>
            <input class='flex-sub invoiceConfirm_fd1_0_c3_c2' type="text" :placeholder="`企业单位税号不能为空`"
              confirm-type="done" :maxlength="-1" placeholder-style="color:#BFBFBF;font-size:32rpx"
              v-model="info.tax_number" />
          </view>
          <view class='flex flex-wrap align-center justify-between invoiceConfirm_fd1_0_c0'>
            <text class='invoiceConfirm_fd1_0_c0_c0'>发票内容</text>
            <text class='invoiceConfirm_fd1_0_c0_c1'>商品明细</text>
          </view>
          <view class='flex flex-wrap align-center invoiceConfirm_fd1_0_c6'>
          </view>
          <view class='flex flex-wrap align-center invoiceConfirm_fd1_0_c3'>
            <image class='invoiceConfirm_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='invoiceConfirm_fd1_0_c3_c1'>联系方式</text>
            <text class='invoiceConfirm_fd1_0_c7_c2'>{{info.mobile}}</text>
          </view>
          <view class='flex flex-wrap align-center invoiceConfirm_fd1_0_c3'>
            <image class='invoiceConfirm_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='invoiceConfirm_fd1_0_c3_c1'>电子邮箱</text>
            <input class='flex-sub invoiceConfirm_fd1_0_c3_c2' type="text" :placeholder="`电子邮箱不能为空`" confirm-type="done"
              :maxlength="-1" placeholder-style="color:#BFBFBF;font-size:32rpx" v-model="info.email" />
          </view>
        </view>
        <view class='flex flex-wrap align-center justify-center invoiceConfirm_fd1_1'>
          <button class='invoiceConfirm_fd1_1_c0' @tap.stop="titleEditFunc()">确认提交</button>
        </view>
      </view>




    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "text": "编辑添加后更新发票列表",
        "info": uni.getStorageSync('invoice') || '',
        "aid": ""
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        aid
      } = options
      if (aid !== undefined) this.aid = aid
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {
      this.info = uni.getStorageSync('invoice') || ''
    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //发票抬头-编辑发票抬头
      async titleEditFunc() {
        if (!validate(this.info.username, 'require')) {
          this.$message.info('请输入发票抬头');
          return false;
        }
        if (this.info.type == '2') {
          if (!validate(this.info.tax_number, 'require')) {
            this.$message.info('请输入企业单位税号');
            return false;
          }
        }
        if (!validate(this.info.email, 'require')) {
          this.$message.info('请输入邮箱');
          return false;
        }
        if (this.aid == '') {
          //请求方法
          //数据验证

          let data641ec735afc0f = await this.$api.dbPost(global.apiUrls.post641ec735afc0f, {
            username: this.info.username,
            tax_number: this.info.tax_number,
            mobile: this.info.mobile,
            email: this.info.email,
            type: this.info.type,
            is_default: this.info.is_default
          });
          if (!data641ec735afc0f) return
          if (data641ec735afc0f.data.code != 1) {
            this.$message.info(data641ec735afc0f.data.msg);
            return
          }



          this.$message.info('添加成功');
        } else {
          //请求方法
          //数据验证

          let data641ec88074922 = await this.$api.dbPost(global.apiUrls.post641ec88074922, {
            aid: this.aid,
            username: this.info.username,
            tax_number: this.info.tax_number,
            mobile: this.info.mobile,
            email: this.info.email,
            type: this.info.type,
            is_default: this.info.is_default
          });
          if (!data641ec88074922) return
          if (data641ec88074922.data.code != 1) {
            this.$message.info(data641ec88074922.data.msg);
            return
          }



          this.$message.info('编辑成功');
        }
        uni.$emit('upinvoice', this.text)
        setTimeout(() => {
          this.$urouter.navigateBack(2);
        }, 800)
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #F8F8F8;
    background-size: 100% auto;
  }

  .invoiceConfirm_flex_0 {
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .invoiceConfirm_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 500;
    color: #333;
  }

  .invoiceConfirm_fd0_0_c0_c0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
  }

  .invoiceConfirm_fd0_0_c0 {
    width: 180rpx;
  }

  .invoiceConfirm_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
  }

  .invoiceConfirm_flex_1 {
    margin: 0rpx 0rpx 32rpx 0rpx;
  }

  .invoiceConfirm_fd1_1_c0 {
    background: var(--benbenbgColor7);
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    font-size: 32rpx;
    color: #fff;
    width: 686rpx;
    height: 88rpx;
    line-height: 88rpx;
    font-weight: 400;
  }

  .invoiceConfirm_fd1_1 {
    position: fixed;
    left: 0rpx;
    bottom: calc(40rpx + var(--window-bottom));
    width: 750rpx;
  }

  .invoiceConfirm_fd1_0_c7_c2 {
    margin: 0rpx 0rpx 0rpx auto;
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 45rpx;
  }

  .invoiceConfirm_fd1_0_c6 {
    background: rgba(248, 248, 248, 1);
    height: 20rpx;
    background-size: 100% auto !important;
  }

  .invoiceConfirm_fd1_0_c3_c2 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 400;
    color: #333;
    text-align: right;
  }

  .invoiceConfirm_fd1_0_c3_c1 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .invoiceConfirm_fd1_0_c3_c0 {
    width: 12rpx;
    height: 12rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 8rpx 0rpx 0rpx;
  }

  .invoiceConfirm_fd1_0_c3 {
    border-bottom: 1px solid #eee;
    margin: 0rpx 32rpx 0rpx 32rpx;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .invoiceConfirm_fd1_0_c2_c1 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 45rpx;
  }

  .invoiceConfirm_fd1_0_c2_c0 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
    margin: 0rpx auto 0rpx 0rpx;
  }

  .invoiceConfirm_fd1_0_c2 {
    border-bottom: 1px solid #eee;
    margin: 0rpx 32rpx 0rpx 32rpx;
    padding: 32rpx 0rpx 32rpx 20rpx;
  }

  .invoiceConfirm_fd1_0_c1_c0 {
    color: var(--benbenFontColor5);
    font-size: 28rpx;
    font-weight: 700;
    line-height: 40rpx;
  }

  .invoiceConfirm_fd1_0_c1 {
    background: rgba(0, 142, 77, 0.1);
    background-size: 100% auto !important;
    padding: 24rpx 52rpx 24rpx 52rpx;
  }

  .invoiceConfirm_fd1_0_c0_c1 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 400;
    color: #333333;
  }

  .invoiceConfirm_fd1_0_c0_c0 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
  }

  .invoiceConfirm_fd1_0_c0 {
    margin: 0rpx 32rpx 0rpx 32rpx;
    padding: 32rpx 0rpx 32rpx 20rpx;
  }

  .invoiceConfirm_fd1_0 {
    background: var(--benbenbgColor1);
    background-size: 100% auto !important;
    margin: 0rpx 0rpx 150rpx 0rpx;
  }
</style>